package com.java.simple.study.juc.p3;

import com.java.simple.study.tool.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhoujl
 * @date 2022/5/9 21:17
 * @desc
 */
@Slf4j(topic = "c.TestThreadStatus")
public class TestThreadStatus {

    final static Object obj = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (obj) {
                log.debug("执行...");
                try {
                    obj.wait();
                    Thread thread = Thread.currentThread();
                    log.debug("状态：{}", thread.getState());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("其它代码...");
            }
        }, "t1").start();

        new Thread(() -> {
            synchronized (obj) {
                log.debug("执行...");
                try {
                    obj.wait();
                    Thread thread = Thread.currentThread();
                    log.debug("状态：{}", thread.getState());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                log.debug("其它代码...");
            }
        }, "t2").start();
        Sleeper.sleep(0.5);
        log.debug("唤醒obj上其它线程");
        synchronized (obj) {
            obj.notifyAll();
        }
    }

}
